package com.ruoyi.directionSys.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.directionSys.domain.TbResearchDirection;
import com.ruoyi.directionSys.service.ITbResearchDirectionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 研究方向Controller
 * 
 * @author ruoyi
 * @date 2025-11-08
 */
@RestController
@RequestMapping("/directionSys/direction")
public class TbResearchDirectionController extends BaseController
{
    @Autowired
    private ITbResearchDirectionService tbResearchDirectionService;

    /**
     * 查询研究方向列表
     */
    @Anonymous
//    @PreAuthorize("@ss.hasPermi('directionSys:direction:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbResearchDirection tbResearchDirection)
    {
        startPage();
        List<TbResearchDirection> list = tbResearchDirectionService.selectTbResearchDirectionList(tbResearchDirection);
        return getDataTable(list);
    }

    /**
     * 导出研究方向列表
     */
    @PreAuthorize("@ss.hasPermi('directionSys:direction:export')")
    @Log(title = "研究方向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbResearchDirection tbResearchDirection)
    {
        List<TbResearchDirection> list = tbResearchDirectionService.selectTbResearchDirectionList(tbResearchDirection);
        ExcelUtil<TbResearchDirection> util = new ExcelUtil<TbResearchDirection>(TbResearchDirection.class);
        util.exportExcel(response, list, "研究方向数据");
    }

    /**
     * 获取研究方向详细信息
     */
    @PreAuthorize("@ss.hasPermi('directionSys:direction:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbResearchDirectionService.selectTbResearchDirectionById(id));
    }

    /**
     * 新增研究方向
     */
    @PreAuthorize("@ss.hasPermi('directionSys:direction:add')")
    @Log(title = "研究方向", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbResearchDirection tbResearchDirection)
    {
        return toAjax(tbResearchDirectionService.insertTbResearchDirection(tbResearchDirection));
    }

    /**
     * 修改研究方向
     */
    @PreAuthorize("@ss.hasPermi('directionSys:direction:edit')")
    @Log(title = "研究方向", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbResearchDirection tbResearchDirection)
    {
        return toAjax(tbResearchDirectionService.updateTbResearchDirection(tbResearchDirection));
    }

    /**
     * 删除研究方向
     */
    @PreAuthorize("@ss.hasPermi('directionSys:direction:remove')")
    @Log(title = "研究方向", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbResearchDirectionService.deleteTbResearchDirectionByIds(ids));
    }
}
